# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=collada-dom
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.0
pkgrel=2
pkgdesc="API that provides a C++ object representation of a COLLADA XML instance document (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/rdiankov/collada-dom/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-uriparser"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-zlib")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
source=("${_realname}.${pkgver}.tar.gz::https://github.com/rdiankov/${_realname}/archive/v${pkgver}.tar.gz"
        001-mingw-w64-fix.patch)
sha256sums=('3be672407a7aef60b64ce4b39704b32816b0b28f61ebffd4fbd02c8012901e0d'
            '8469ebf0a5f6309d29a073117cac995324b99ec62a09e2b9501282c358d3fbd6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/001-mingw-w64-fix.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  CXXFLAGS+=" -Wno-deprecated-declarations" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${_extra_config[@]} \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/licenses/license_e.txt" \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
